Setting watchpoints

Contents|Index|Previous|Next
Setting watchpoints

You can use a watchpoint to stop execution whenever the value of an expression changes, without having to predict a particular place where this may happen.

Watchpoints currently execute two orders of magnitude more slowly than other breakpoints, but this can be well worth it to catch errors where you have no clue what part of your program is the culprit.

watch `expr`

Set a watchpoint for an expression, `expr`. GDB will break when `expr` is written into by the program and its value changes. This can be used with the new trap-generation provided by SPARClite DSU. DSU will generate traps when a program accesses some date or instruction address that is assigned to the debug registers. For the data addresses, DSU facilitates the watch command. However the hardware breakpoint registers can only take two data watchpoints, and both watchpoints must be the same kind. For example, you can set two watchpoints with watch commands, two with rwatch commands, or two with awatch commands, but you cannot set one watchpoint with one command and the other with a different command. GDB will reject the command if you try to mix watchpoints. Delete or disable unused watchpoint commands before setting new ones.

rwatchexpr

Set a watchpoint that will break when watch args is read by the program. If you use both watchpoints, both must be set with the rwatch command.

awatchexpr

Set a watchpoint that will break when args is read and written into by the program. If you use both watchpoints, both must be set with the awatch command.

infowatchpoints

This command prints a list of watchpoints, breakpoints and catchpoints; it is the same as info break.

Warning:
In multi-thread programs, watchpoints have only limited usefulness. With the current watchpoint implementation, GDB can only watch the value of an expression in a single thread. If you are confident that the expression can only change due to the current thread’s activity (and if you are also confident that no other thread can become current), then you can use watchpoints as usual. However, GDB may not notice when a non-current thread’s activity changes the expression.

Top|Contents|Index|Previous|Next